package com.yusheng.tr.multi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yusheng.tr.common.core.entity.multi.ReportLogEntity;
import com.yusheng.tr.multi.mapper.ReportLogMapper;
import com.yusheng.tr.multi.service.IReportLogService;
import com.yusheng.tr.common.core.model.vo.multi.ReportLogVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 报表日志表 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-10-05
 */
@Service
public class ReportLogServiceImpl extends ServiceImpl<ReportLogMapper, ReportLogEntity> implements IReportLogService {
    @Autowired
    private ReportLogMapper reportLogMapper;

    /**
     * 查询结算日志
     *
     * @param reportLogEntity
     * @return
     */
    @Override
    public List<ReportLogEntity> queryReport(ReportLogEntity reportLogEntity) {
        QueryWrapper<ReportLogEntity> queryWrapper = new QueryWrapper<>(reportLogEntity);
        return reportLogMapper.selectList(queryWrapper);
    }

    /**
     * 对结算单，结算单日志进行VO分页查询
     */
    @Override
    public PageInfo<ReportLogEntity> queryPage(Integer pageNum, Integer pageSize, ReportLogVO reportLogVO) {
        LambdaQueryWrapper<ReportLogEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(reportLogVO.getOperator()), ReportLogEntity::getCreateBy, reportLogVO.getOperator())
                .eq(StringUtils.isNotBlank(reportLogVO.getType()), ReportLogEntity::getOperationType, reportLogVO.getType())
                .eq(StringUtils.isNotBlank(reportLogVO.getIpAddress()), ReportLogEntity::getIpAddress, reportLogVO.getIpAddress())
                .between(
                        reportLogVO.getStartTime() != null && reportLogVO.getEndTime() != null,
                        ReportLogEntity::getCreateTime, reportLogVO.getStartTime(), reportLogVO.getEndTime())
                .like(StringUtils.isNotBlank(reportLogVO.getFormName()), ReportLogEntity::getStmtId, reportLogVO.getFormName())
                        .orderByDesc(ReportLogEntity::getCreateTime);
       PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(list(queryWrapper));

    }
}
